<template>
  <div>
    <el-table :data="leaveList" stripe style="width: 100%">

      <el-table-column prop="id" label="ID" width="200"></el-table-column>
      <el-table-column prop="doctorName" label="医生名称" width="200"></el-table-column>
      <el-table-column prop="departmentName" label="所属科室" width="200"></el-table-column>
      <el-table-column prop="reason" label="请假原因" width="200"></el-table-column>


      <el-table-column label="请假信息" width="300">
        <template slot-scope="scope">
          <div>
            <span v-if="scope.row.timengStatus == 1">{{scope.row.nowTime }}  (全天)  </span>
            <span v-else-if="scope.row.timengStatus == 2">{{scope.row.nowTime }} (上午) </span>
            <span v-else-if="scope.row.timengStatus == 3">{{scope.row.nowTime }} (下午) </span>
            <span v-else>无</span>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="nowDate" label="提交时间" width="200"></el-table-column>

      <el-table-column label="状态" align="center" prop="shiftType">
        <template slot-scope="scope">
          <span v-if="scope.row.status==1">待审核</span>
          <span v-if="scope.row.status==2">通过</span>
          <span v-if="scope.row.status==3">驳回</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" v-if="scope.row.status==1" type="text" icon="el-icon-edit" @click="pass(scope.row)" v-hasPermi="['schedule:schedule:edit']">通过</el-button>
          <el-button size="mini" v-if="scope.row.status==1" type="text" icon="el-icon-delete" @click="reject(scope.row)" v-hasPermi="['schedule:schedule:remove']">驳回</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>


<script>
import {approveLeave, getLeaveList} from "@/api/appointment/leave/leave";

export default {
  name: "Leave",

  data() {
    return {
      loading: true,
      leaveList: [],
      leave:{
        id:null,
        status:null,
        timeId:null,
        doctorId:null,
        timengStatus:null,
      }
    };
  },

  created() {
    this.getList();
  },

  methods: {
    // 通过
    pass(row){
      this.leave.status = 1
      this.leave.timengStatus = row.timengStatus
      this.leave.doctorId = row.doctorId
      this.leave.id = row.id
      this.leave.timeId = row.timeId
      approveLeave(this.leave).then(response => {
        this.$message.success("审核通过")
        this.getList();
      })
    },
    // 驳回
    reject(row){
      this.leave.status = 2
      this.leave.timengStatus = row.timengStatus
      this.leave.doctorId = row.doctorId
      this.leave.id = row.id
      this.leave.timeId = row.timeId
      approveLeave(this.leave).then(response => {
        this.$message.success("驳回")
        this.getList();
      })
    },
    /** 查询请假记录 */
    getList() {
      getLeaveList().then((res) => {
        this.leaveList = res.data;
      });
    },
  },
};
</script>
